package com.briup.corejava.day17;

import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * JDK中默认的线程池的使用
 */
public class Test1 {
    public static void main(String[] args) {
        ExecutorService es = Executors.newFixedThreadPool(2);
        Runnable r = new Mr();
        System.out.println(es.getClass());
        es.submit(r);
        es.submit(r);
        es.submit(r);
        es.submit(r);
        es.submit(r);
        // 销毁线程池
        es.shutdown();
    }
}
// 提供任务
class Mr implements Runnable{

    @Override
    public void run(){
        String name = Thread.currentThread().getName();
        System.out.println("我需要一个教练【"+name+"】");
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("教练教完了，回到游泳池");
    }
}
